package com.autosalon.model;

import java.io.Serializable;
import java.sql.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "AUTOMOBIL")
public class Automobil implements Serializable, IModelClass{
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@ManyToOne(cascade= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
	@JoinColumn(name = "ID_MODELU")
	private Model model;
	
	@Column(name="CENA", nullable=false)
	private int cena;
	
	@Column(name="DATUM_VYROBY", nullable=false)
	private Date datumVyroby;
	
	@Column(name="NAJETO", nullable=false)
	private int najeto;
	
	@ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH}, fetch=FetchType.EAGER)
	@JoinTable(name = "ZAKLADNI_VYBAVA", 
				joinColumns={ 
								@JoinColumn(name = "ID_AUTOMOBILU") 
							}, 
				inverseJoinColumns={ 
								@JoinColumn(name = "ID_DOPLNKU")
								}
	)
	private List<Doplnek> zakladni_vybava;
	
	@OneToMany(cascade=CascadeType.ALL)
	@JoinColumn(name="ID_AUTOMOBILU")
	private List<Objednavka> objednavky;
        
	public List<Doplnek> getZakladni_vybava() {
		return zakladni_vybava;
	}

	public void setZakladni_vybava(List<Doplnek> zakladni_vybava) {
		this.zakladni_vybava = zakladni_vybava;
	}

	@Override
	public Long getId() {
		return id;
	}

	public Model getModel() {
		return model;
	}

	public void setModel(Model model) {
		this.model = model;
	}

	public int getCena() {
		return cena;
	}

	public void setCena(int cena) {
		this.cena = cena;
	}

	public Date getDatumVyroby() {
		return datumVyroby;
	}

	public void setDatumVyroby(Date datumVyroby) {
		this.datumVyroby = datumVyroby;
	}

	public int getNajeto() {
		return najeto;
	}

	public void setNajeto(int najeto) {
		this.najeto = najeto;
	}

	public List<Objednavka> getObjednavky() {
		return objednavky;
	}

	public void setObjednavky(List<Objednavka> objednavky) {
		this.objednavky = objednavky;
	}

    @Override
    public String toString() {
        return model.getVyrobce().getNazev_vyrobce() + " " + model.getNazev_modelu();
    }
        
        
        
	
	
	

}
